/*
 * ========================================================================
 *
 *       Filename:  cstmtxtctrl.cpp
 *
 *    Description:  This defines the custom text control for the testboard.
 *                  Essentially, it allows shift+enter to insert enter
 *                  while still allowing events on enter without shift.
 *
 *        Version:  1.0
 *        Created:  05/25/2010 08:17:02 PM
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  Alex Avance (aa), aravance@gmail.com
 *        Company:  independent
 *
 * ========================================================================
 *
 * Copyright (C) 2010 Alex Avance
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 * ========================================================================
 */

#include "wx/defs.h"
#include "cstmtxtctrl.h"

BEGIN_EVENT_TABLE( CustomTextCtrl, wxTextCtrl )
  EVT_KEY_DOWN( CustomTextCtrl::OnChar )
END_EVENT_TABLE()

/**************************************************************************
Class Name: CustomTextCtrl
Method Name: CustomTextCtrl
Description: constructor
**************************************************************************/
CustomTextCtrl::CustomTextCtrl ( wxWindow *parent, wxWindowID id, const wxString &value,
                                 const wxPoint &pos, const wxSize &size, long style,
                                 const wxValidator &validator, const wxString &name )
  : wxTextCtrl( parent, id, value, pos, size, style | wxWANTS_CHARS, validator, name )
{} // ----- end of method CustomTextCtrl::CustomTextCtrl (constructor) -----

/**************************************************************************
Class: CustomTextCtrl
Method: OnChar
Description: Process key events. Essentially, shift with enter generates
             a new line. Otherwise, let it be processed normally.
**************************************************************************/
void CustomTextCtrl::OnChar ( wxKeyEvent &event )
{
  if ( event.GetKeyCode() == WXK_RETURN && event.GetModifiers() == wxMOD_SHIFT )
    EmulateKeyPress( event );
  else
    event.Skip();
} // ----- end of method CustomTextCtrl::OnChar -----

/**************************************************************************
Class: CustomTextCtrl
Method: SetFocusFromKbd
Description: This handles acquiring focus with tab. It selects all text.
**************************************************************************/
void CustomTextCtrl::SetFocusFromKbd ()
{
  SetSelection( -1, -1 );
  wxWindow::SetFocusFromKbd();
} // ----- end of method CustomTextCtrl::SetFocusFromKbd -----

